package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.third.bairong.BairongInterestRatePreferenceData;
import com.ucredit.babel.common.model.third.bairong.BairongInterestRatePreferenceFinalData;
import com.ucredit.babel.common.model.third.bairong.BairongInterestRatePreferenceRecord;
import com.ucredit.babel.common.model.third.bairong.BairongInterestRatePreferenceScoreData;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/*
 * 百融利率偏好评估
 *
 * @author:guoqiang
 * */

public class BairongInterestRatePreferenceParse extends ParseBase{
    private Text val = new Text();
    private Text key = new Text();

    /**
     * @param context
     * @param model
     * @param successful
     * @return
     * @throws IOException
     * @throws InterruptedException
     */

    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        BairongInterestRatePreferenceRecord brRecord = (BairongInterestRatePreferenceRecord) model;
        BairongInterestRatePreferenceData brData = brRecord.getData();
        StringBuilder sb = getBaseInfo(brRecord, successful);
        StringBuilder brSb = new StringBuilder(2000);
        brSb.append(brData.getCode() == null ? "" : brData.getCode()).append(CRT001);
        brSb.append(brData.getSwiftNumber() == null ? "" : brData.getSwiftNumber()).append(CRT001);
        brSb.append(brData.getFlag().getScore() == null ? "" : brData.getFlag().getScore()).append(CRT001);
        brSb.append(brData.getFlag().getScoreData() == null ? "" : brData.getFlag().getScoreData()).append(CRT001);
        brSb.append(brData.getScore().getModelpmixinterestprefer() == null ? "" : brData.getScore().getModelpmixinterestprefer()).append(CRT001);

        BairongInterestRatePreferenceScoreData score12ScoreData = brData.getScoreData();
        if(score12ScoreData != null){
            BairongInterestRatePreferenceFinalData score12ScoreDataDetail = score12ScoreData.getModelpmixinterestprefer();
            if(score12ScoreDataDetail != null){
                brSb.append(score12ScoreDataDetail.getFlagAlt() == null ? "" : score12ScoreDataDetail.getFlagAlt()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getAltM1RiskWeightavg() == null ? "" : score12ScoreDataDetail.getAltM1RiskWeightavg()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getAltM3RiskWeightavg() == null ? "" : score12ScoreDataDetail.getAltM3RiskWeightavg()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getAltM6RiskWeightavg() == null ? "" : score12ScoreDataDetail.getAltM6RiskWeightavg()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getAltM9RiskWeightavg() == null ? "" : score12ScoreDataDetail.getAltM9RiskWeightavg()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getAltM12RiskWeightavg() == null ? "" : score12ScoreDataDetail.getAltM12RiskWeightavg()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getAltM1RiskStd() == null ? "" : score12ScoreDataDetail.getAltM1RiskStd()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getAltM3RiskStd() == null ? "" : score12ScoreDataDetail.getAltM3RiskStd()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getAltM6RiskStd() == null ? "" : score12ScoreDataDetail.getAltM6RiskStd()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getAltM9RiskStd() == null ? "" : score12ScoreDataDetail.getAltM9RiskStd()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getAltM12RiskStd() == null ? "" : score12ScoreDataDetail.getAltM12RiskStd()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getAltM1RiskLevelhighest() == null ? "" : score12ScoreDataDetail.getAltM1RiskLevelhighest()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getAltM3RiskLevelhighest() == null ? "" : score12ScoreDataDetail.getAltM3RiskLevelhighest()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getAltM6RiskLevelhighest() == null ? "" : score12ScoreDataDetail.getAltM6RiskLevelhighest()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getAltM9RiskLevelhighest() == null ? "" : score12ScoreDataDetail.getAltM9RiskLevelhighest()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getAltM12RiskLevelhighest() == null ? "" : score12ScoreDataDetail.getAltM12RiskLevelhighest()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getAltM1RiskLevellowest() == null ? "" : score12ScoreDataDetail.getAltM1RiskLevellowest()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getAltM3RiskLevellowest() == null ? "" : score12ScoreDataDetail.getAltM3RiskLevellowest()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getAltM6RiskLevellowest() == null ? "" : score12ScoreDataDetail.getAltM6RiskLevellowest()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getAltM9RiskLevellowest() == null ? "" : score12ScoreDataDetail.getAltM9RiskLevellowest()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getAltM12RiskLevellowest() == null ? "" : score12ScoreDataDetail.getAltM12RiskLevellowest()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getAltT5RiskWeightavg() == null ? "" : score12ScoreDataDetail.getAltT5RiskWeightavg()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getAltT10RiskWeightavg() == null ? "" : score12ScoreDataDetail.getAltT10RiskWeightavg()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getAltT5RiskStd() == null ? "" : score12ScoreDataDetail.getAltT5RiskStd()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getAltT10RiskStd() == null ? "" : score12ScoreDataDetail.getAltT10RiskStd()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getAltT5RiskLevelhighest() == null ? "" : score12ScoreDataDetail.getAltT5RiskLevelhighest()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getAltT10RiskLevelhighest() == null ? "" : score12ScoreDataDetail.getAltT10RiskLevelhighest()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getAltT5RiskLevellowest() == null ? "" : score12ScoreDataDetail.getAltT5RiskLevellowest()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getAltT10RiskLevellowest() == null ? "" : score12ScoreDataDetail.getAltT10RiskLevellowest()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getAltT1T5Timespan() == null ? "" : score12ScoreDataDetail.getAltT1T5Timespan()).append(CRT001);
                brSb.append(score12ScoreDataDetail.getAltT1T10Timespan() == null ? "" : score12ScoreDataDetail.getAltT1T10Timespan()).append(CRT001);
            } else {
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
                brSb.append(CRT001);
            }
        }else{
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
            brSb.append(CRT001);
        }
        key.set(getKey());
        val.set((sb.toString() + brSb.toString()).replace("\n", " ").replace("\r", " "));
        context.write(key, val);

        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_br_interest_rate_preference_record_inc";
    }

    @Override
    public String getType() {
        return RecordType.BAIRONG_INTEREST_RATE_PREFERENCE_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "百融利率偏好评估";
    }
}
